var mapWidth = 150;
var mapHeight = 130;

function ShowMinimap(sessionId, mapName, mapDefinition, scale, x1, y1, x2, y2)
{
	if(x1)
	{
		var geomtext = "5,"+x1+","+y1+","+x1+","+y2+","+x2+","+y2+","+x2+","+y1+","+x1+","+y1;
		var reqParams = "SESSION=" + sessionId + "&MAPNAME=" + encodeURIComponent(mapName) + "&SEQ=" + Math.random() + "&GEOMTEXT=" + geomtext;
		var mapId=0;

		mr = CreateRequestHandler();
		req = new MapRequest(mr, mapId);
		mr.open("POST", "/mapguide/mapviewernet/createoverviewext.aspx", true);
		mr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		mr.onreadystatechange = function(){
			if(mr.readyState == 4)
			{
				RequestMinimapImage(req, sessionId, mapName, mapDefinition, scale);
			}
		}
		try{mr.send(reqParams);}
		catch(e){return;}
	}
	else
	{
		RequestMinimapImage(req, sessionId, mapName, mapDefinition, scale);
	}
}
function RequestMinimapImage(request, sessionId, mapName, mapDefinition, scale)
{
	try{
		var test_param = request.reqObj.responseText;
		//var imageUrl = webAgent+"?OPERATION=GETMAPIMAGE&VERSION=1.0.0&SESSION="+sessionId+"&MAPNAME="+mapName+"&LOCALE=en&MAPDEFINITION"+mapDefinition+"=&FORMAT=GIF&SELECTION=&SETVIEWCENTERX="+X+"&SETVIEWCENTERY="+Y+"&SETVIEWSCALE="+scale*6+"&SETDISPLAYDPI=75&SETDISPLAYWIDTH=130&SETDISPLAYHEIGHT=160&SHOWLAYERS="+test_param+"&HIDELAYERS=&SHOWGROUPS=&HIDEGROUPS=";
		var imageUrl = webAgent+"?OPERATION=GETMAPIMAGE&VERSION=1.0.0&SESSION="+sessionId+"&MAPNAME="+mapName+"&LOCALE=en&MAPDEFINITION"+mapDefinition+"=&FORMAT=GIF&SELECTION=&SETVIEWCENTERX=&SETVIEWCENTERY=&SETVIEWSCALE="+scale+"&SETDISPLAYDPI=75&SETDISPLAYWIDTH="+mapWidth+"&SETDISPLAYHEIGHT="+mapHeight+"&SHOWLAYERS="+test_param+"&HIDELAYERS=&SHOWGROUPS=&HIDEGROUPS=";
		document.getElementById("minimap").style.backgroundImage = 'url("")';        
	}catch(e){
		//imageUrl1 = webAgent+"?OPERATION=GETMAPIMAGE&VERSION=1.0.0&SESSION=&MAPNAME=TestMap&LOCALE=en&MAPDEFINITION=Library://GevautAlonim/BirElMacsur/Maps/BirElMacsur.MapDefinition&FORMAT=PNG&SELECTION=&SETVIEWCENTERX=&SETVIEWCENTERY=&SETVIEWSCALE=80000&SETDISPLAYDPI=75&SETDISPLAYWIDTH=150&SETDISPLAYHEIGHT=150&SHOWLAYERS=31e1c2d6-0000-1000-8004-005056c00008&HIDELAYERS=&SHOWGROUPS=&HIDEGROUPS=";
	}
	document.getElementById("minimap").style.backgroundImage = 'url(' + imageUrl + ')';
	timeout = window.setTimeout("ClearMinimapExt('"+sessionId+"', '"+mapName+"')", 2000);
}
function ClearMinimapExt(sessionId, mapName)
{
	var mapId=0;
	var reqParams = "SESSION=" + sessionId + "&MAPNAME=" + encodeURIComponent(mapName);
	mr = CreateRequestHandler();
	req = new MapRequest(mr, mapId);
	mr.open("POST", "/mapguide/mapviewernet/deleteoverviewext.aspx", true);
	mr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	try{mr.send(reqParams);}
	catch(e){return;}
	window.clearTimeout(timeout);
}

function CreateRequestHandler()
{
    return new XMLHttpRequest();
}
function MapRequest(reqObj, mapId)
{
    this.reqObj = reqObj;
    this.mapId = mapId;
}

